package practise;

import java.util.ArrayList;
import java.util.List;

public class PreorderTraversal {
    public List<Integer> preorderTraversal(TreeNode root) {
        ArrayList<Integer> list = new ArrayList<>();
        if(root == null) {
            return list;
        }
        list.add(root.val);
        List<Integer> list1 = preorderTraversal(root.left);
        List<Integer> list2 = preorderTraversal(root.right);
        list.addAll(list1);
        list.addAll(list2);
        return list;
    }
}
